﻿
using FreeSql.DataAnnotations;
using Rswl.Common.Core.User.Aggregate.ValueObject;

namespace Rswl.Common.Core.User.Aggregate.Entities
{
    [Table(Name ="rswl_user_info")]
   
    public partial class UserInfo
    {
        [Column(IsPrimary =true,IsIdentity =false)]
        public string UserId { get; set; }
        
        public string UserName { get; set; }
     
        public string TrueName { get; set; } = "";
        string avatar = "";
       
        public string Avatar { get {
                if(!string.IsNullOrWhiteSpace(avatar))
                {
                    if(avatar.StartsWith("http://"))
                    {
                        avatar = avatar.Replace("http://", "https://");
                    }
                }
                return avatar;
            } set {
                avatar = value;
            } } 
         
        public string Nick { get; set; } = "";
       
        public string Phone { get; set; } = "";
       
        public DateTime RegisterDate { get; set; } = DateTime.Now;
       
        public string Email { get; set; } = "";

       
        public string Remark { get; set; } = "";

        /// <summary>
        /// 原始角色
        /// </summary>
        public UserRole Role { get; set; }
        /// <summary>
        /// 自定义用户角色
        /// 支持多角色
        /// </summary>
        public string UserRoles { get; set; }

        public int Grade { get; set; }
       
        public DateTime? VipEndDate { get; set; }

        
        public string InviteUserId { get; set; } = "";

        
        /// <summary>
        /// 邀请码
        /// </summary>
         
        public string InviteCode { get; set; } = "";
        [Navigate(nameof(UserInfo.UserId))]
        public List<UserExtInfo> UserExtInfos { get; set; }

        int fileSizeLimit = 300;
       
        /// <summary>
        /// 上传文件权限
        /// </summary>
        [Column(IsIgnore =true)]
        public int FileSizeLimit { 
            get {
                //if(Role== UserRole.Admin)
                //{
                //    fileSizeLimit = 102400;
                //}else
                //{
                //    if(Grade== UserGrade.VIP1)
                //    {
                //        fileSizeLimit = 500;
                //    }
                //    if (Grade == UserGrade.VIP2)
                //    {
                //        fileSizeLimit = 1024;
                //    }
                //    if (Grade == UserGrade.VIP5)
                //    {
                //        fileSizeLimit = 10240;
                //    }
                //}
                return fileSizeLimit;
            } }
        public string CreateInviteCode()
        {
           return new RsCode.Helper.IdGenerate().NewId().ToString();
        }
        /// <summary>
        /// 帐号状态 0禁用 1启用
        /// </summary>
        public int Status { get; set; }=1;
    }
}
